package org.wj.example;

import akka.actor.AbstractActor;
import akka.actor.ActorRef;
import akka.actor.Status;
import akka.event.Logging;
import akka.event.LoggingAdapter;
import akka.japi.pf.ReceiveBuilder;

public class JavaPongActor extends AbstractActor {

    protected final LoggingAdapter log = Logging.getLogger(context().system(), this);

    @Override
    public Receive createReceive() {
        return ReceiveBuilder.create().matchEquals("Ping", s -> {
            ActorRef sender = sender();
            log.info(sender.toString());
            sender.tell("Pong", self());
        }).matchAny(x->sender().tell(new Status.Failure(new Exception("unknown message")), self())).build();
    }


}
